<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd" lang="fr">

<wicket:head>
	<title>Navigation à travers les services</title>
	
	<wicket:link>
		<script type="text/javascript">
			var first = false;

			function callWicket() {
				var wcall = wicketAjaxGet('$url$' + '$args$', 
						/**/function() { }, /**/function() { });
			};
			
			$(function () {
				$("#treeview").jstree({ 
					plugins : [ "themes", "cookies", "ui", "json_data", "contextmenu" ],
					themes : {
						theme: "classic"
					},
					json_data: {
						progressive_render: true,
						data: [
						         {
	                    			data : "Ministère",
	                    			attr : {
	                    				id : "0"
	                    			},
	                    			state : "closed"
	                			}
						],
						ajax : {
							async: true,
							url: "browse?nocache="+Math.random(),
							datatype: "json",
							data: function (n) {
								return { id : n.attr ? n.attr("id") : 0 };
							}
						}
					},
					contextmenu : {
						items : function(obj) {
							var menu = {};
							var nodeId = obj.attr('id');
							var nodeRel = obj.attr('rel');
							if (nodeId != '0' && nodeRel != 'disabled') {
								menu = {
									"ccp" : false,
									"rename" : false,
									"edit" : {
										label : "Editer",
										icon : "styles/plugins/buttons/icons/edit.png",
										action : function (obj) { 
												var nodeId = obj.attr('id');
												document.location.href = obj.attr('editUrl');
												return true;
											},
										_disabled : false,
										separator_after : true
									},
									"create" : {
										label : "Créer",
										icon : "styles/plugins/buttons/icons/add.png",
										action : function (obj) {
												var nodeId = obj.attr('id');
												document.location.href = obj.attr('createUrl');
												return true;
											},
										_disabled : false,
										separator_after : true
									},
									"remove" : {
										label : "Supprimer",
										icon : "styles/plugins/buttons/icons/delete.png",
										action : function (obj) { 
												var nodeId = obj.attr('id');
												document.location.href = obj.attr('deleteUrl');
												return true;
											},
										_disabled : false
									}
								}
							}
							
							return menu;
						}
					},
					core : {
						html_titles : true,
						strings : {
							loading : "Chargement en cours..."
						}
					},
					cookies : {
						save_selected : "true"
					}
				});

/*
				$("#treeview").bind("reselect.jstree", function(event, data) {
			        first = true;
				});
*/
				$("#treeview").bind("select_node.jstree", function(e,data) {
					var href = data.rslt.obj.attr("href");
			        var path = window.location.href;
			        id = data.rslt.obj.attr("id");
			        document.location.href = path + "&id=" + id;
			        return true;
				});
/*
				$("#treeview").bind("select_node.jstree", function(event, data) {
					if (!first) {
				    	return;
				    } 
					var href = data.rslt.obj.attr("href");
			        var path = window.location.href;
			        alert("id: " + data.rslt.obj.attr("id"));
			        alert("path: " + path);
			        id = data.rslt.obj.attr("id");
			        document.location.href = href + "&id=" + id;
			        return true;
			    });
*/
			});
		</script>
	</wicket:link>
</wicket:head>

<body>

<wicket:extend>
  <div class="span-6" id="treeview-wrapper">
	<span id="treeview" wicket:id="treeview"></span>
  </div>
<!--  <input value="Recharger" onclick="$('#treeview').jstree('refresh', -1);" type="button">-->
  
  <div class="content span-18 last">
  	<span wicket:id="viewServicePanel"></span>
  <!-- @TODO AJOUTER ICI LES PANELS -->
  </div>
</wicket:extend>
</body>
</html>

